const jwt = require("jsonwebtoken");

module.exports.Msg = function(status, msg, data) {
    return status == 200 ? { status, msg, data } : { status, msg };
}

module.exports.curPath = 'http://localhost:3000/';


let jwtKey ="zqw@ajdkal123."

module.exports.createJWT = function(uid, uname) {
    //expirseIn:有效时间 时间单位为秒
    return jwt.sign({ uid, uname }, jwtKey, { expiresIn: 60 * 60 * 24 });
}

//使用JWT数据：jwt.verify( jwt数据,密钥 )
module.exports.useJWT = function(jwtdatas) {

    try {
        let jwtObj = jwt.verify(jwtdatas, jwtKey);
        if (jwtObj) {
            return jwtObj;
        } else {
            return false;
        }
    } catch (error) {
        console.log(error);
        return false;
    }
}